<template>
	<section>
		<div>1</div>
	</section>
</template>

<script>
	import Stack from '../../assets/script/structure/stack.js'
	import BinaryTree from '../../assets/script/structure/binaryTree.js'

	export default {
		methods: {
			init () {
				function Person () {
					this.name = "defore"
					this.age = 24
					this.speak = function (words) {
						console.log(words)
					}
				}

				Person.sayHello = function (words) {
					this.speak(words)
				}

				let person = new Person()
				person.sayHello("demo")

				function sayHello (words) {
					let person = new Person()
					person.speak(words)
				}
				// sayHello("hello Tim!")
			},
			// 堆栈
			stackFn () {
				/*
				let stack = new Stack()

				stack.push(1)
				stack.push(2, 3)
				console.log(stack.data)

				stack.pop()
				console.log(stack.data)
				console.log(stack.peek())
				stack.clear()
				console.log(stack.data)
				*/

				// 进制数转换
				/*
				const numConvert = (num, base) => {
					const stack = new Stack()
					let converted = ''

					while (num > 0) {
						stack.push(num % base)
						num = Math.floor(num / base)
					}

					while(stack.length() > 0) {
						converted += stack.pop()
					}

					return +converted
				}
				console.log(numConvert(10, 2))
				*/

				// 判断文章是否为回文串
				const isPalindrome = words => {
					const stack = new Stack()
					let wordsCopy = ''
					words = words.toString()

					Array.prototype.forEach.call(words, word => stack.push(word))

					while (stack.length() > 0) {
						wordsCopy += stack.pop()
					}
					return words === wordsCopy
				}

				console.log(isPalindrome('1a121a1'))
				console.log(isPalindrome(1232))
			},
			binaryTreeFn () {
				const data = [8, 3, 10, 1, 6, 14, 4, 7, 13]

				const binaryTree = new BinaryTree()

				data.forEach(item => binaryTree.insert(item))

				console.log(binaryTree.root)
			}
		},
		mounted () {
			// this.init()
			// this.stackFn()
			this.binaryTreeFn()
		}
	}
</script>

<style lang="scss" scoped>

</style>
